home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cocktail / mpp.lha / mpp / src / Scanner.mi < prev    next >
Text File  |  1992-08-18  |  1KB  |  70 lines

  1. (* $Id: Scanner.mi,v 1.4 1991/03/08 18:47:44 grosch rel $ *)
  2.  
  3. IMPLEMENTATION MODULE Scanner;
  4.  
  5. FROM IO    IMPORT StdInput, ReadC;
  6.  
  7. CONST
  8.   cEof = 0C;
  9.   cTab = 11C;
  10.   cEol = 12C;
  11.  
  12. VAR
  13.   next, ch: CHAR;
  14.  
  15. PROCEDURE BeginScanner;
  16.   BEGIN
  17.     next := ReadC (StdInput);
  18.     ch := cEol;
  19.   END BeginScanner;
  20.  
  21. PROCEDURE CloseScanner;
  22.   END CloseScanner;
  23.  
  24. PROCEDURE GetToken (): CARDINAL;
  25.   BEGIN
  26.     LOOP
  27.       IF ch = cEof THEN
  28.     RETURN 0;
  29.       ELSIF ch = cEol THEN
  30.     INC (Attribute.Position.Line);
  31.     Attribute.Position.Column := 0;
  32.       ELSIF ch = cTab THEN
  33.     Attribute.Position.Column := (Attribute.Position.Column DIV 8 + 1) * 8
  34.       END;
  35.       INC (Attribute.Position.Column);
  36.       ch := next;
  37.       next := ReadC (StdInput);
  38.       CASE ch OF
  39.       | cEof:        RETURN 0;
  40.       | ' ':        RETURN 1;
  41.       | '^':        RETURN 2;
  42.       | '%':        RETURN 3;
  43.       | '$':        RETURN 4;
  44.       | '.':        RETURN 5;
  45.       | '\':        IF next = cEol THEN
  46.               ch := next;
  47.               next := ReadC (StdInput);
  48.               RETURN 10;
  49.             ELSE
  50.               RETURN 6;
  51.             END;
  52.       | '{':        RETURN 7;
  53.       | '}':        RETURN 8;
  54.       | cEol:        RETURN 9;
  55.       | cTab:        RETURN 12;
  56.       ELSE        Attribute.Ch := ch; RETURN 11;
  57.       END;
  58.     END;
  59.   END GetToken;
  60.  
  61. PROCEDURE ErrorAttribute (Symbol: CARDINAL; VAR Attribute: tScanAttribute);
  62.   BEGIN
  63.     Attribute.Ch := ' ';
  64.   END ErrorAttribute;
  65.  
  66. BEGIN
  67.   Attribute.Position.Line := 0;
  68.   Attribute.Position.Column := 0;
  69. END Scanner.
  70.